<?php

namespace bdd;

class Connection {

    private $_link;

    public static function getConnection() {
        static $conn = null;
        if ($conn == null)
            $conn = new Connection();
        return $conn;
    }

    private function __construct() {
        $host = 'localhost';
        $user = 'root';
        $pass = null;
        $db = 'test';

        $this->_link = new \pdo("mysql:host=$host;dbname=$db", $user, $pass);
        if (!$this->_link) {
            echo 'Connexion échouée';
            die();
        }
    }

    public function ExecQuery($query) {
        $PdoStatement = $this->_link->query($query);
        return $PdoStatement;
    }

    public function ExecStoredPreparedQuery($name, $param) {
        $dir = 'bdd';
        $query = $QUERY[$dir][$name];
        $PdoStatement = $this->_link->prepare($query->query);

        $PdoStatement->execute($param);
    }

    public function prepareQuery($query) {
        return $this->_link->prepare($query);
    }

    public function getLink() {
        return $this->_link;
    }

}

?>